﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using EZCRS.HCMS.Bll;
using EZCRS.HCMS.Entity;
using EZCRS.HCMS.Bll.baseinfo;
using EZCRS.HCMS.Web;

namespace EZCRS.HCMS.Web.manage.hotel
{
    public partial class guaruleadd : ManageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (base.BasHotelId == 0)
                Response.Write(CFun.AlertMeg(Resources.Site.MustHotel, "back", ""));

            if (!Page.IsPostBack)
            {
                CFun.SetListControl(ddlGperiod, Bllbase_info.getbaseinfo(baseinfotype.保证金时期, CFun.CurrentLanguage()), "");
                CFun.SetListControl(ddlGType, Bllbase_info.getbaseinfo(baseinfotype.保证金类型措施, CFun.CurrentLanguage()), "");

                btnsave.Text = Resources.Site.ButtonSave;

                int id = CFun.RequestNumber("id");
                HCRS_GuaRule _guarule = new BllH_guarule().getitem(id);
                if (_guarule != null)
                {
                    hidid.Value = id.ToString();
                    CFun.bindpagedata<HCRS_GuaRule>(this, _guarule);

                    btnsave.Text = Resources.Site.ButtonModify;
                    btndel.Visible = true;
                    btndel.Attributes.Add("onclick", "return confirm('" + Resources.Site.SystemConfirmDelete + "');");
                }
            }
        }

        protected void btnsave_Click(object sender, EventArgs e)
        {
            HCRS_GuaRule _guarule = new HCRS_GuaRule();
            CFun.getpagedata<HCRS_GuaRule>(_guarule, this);
            _guarule.Property_id = base.BasPropertyId;
            _guarule.updatetime = DateTime.Now;
            _guarule.userid = base.BasUserId;
            _guarule.languagetype = base.LanguageId;
            
            if (new BllH_guarule().insertorupdateitem(_guarule))
                Page.ClientScript.RegisterClientScriptBlock(typeof(String), "scuress", CFun.AlertMeg(Resources.Site.SystemModifySuccess, "", "guarule.aspx"));
            else
                Response.Write(CFun.AlertMeg(Resources.Site.SystemError, "back", ""));
        }

        protected void btndel_Click(object sender, EventArgs e)
        {
            if(new BllH_guarule().deleteitem(Convert.ToInt32(hidid.Value)))
                Response.Write(CFun.AlertMeg(Resources.Site.SystemDeleteSuccess, "", "guarule.aspx"));
            else
                Response.Write(CFun.AlertMeg(Resources.Site.SystemError, "back", ""));
        }
    }
}
